﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

    public class CHITIET_PHIEUXUAT_DATAACCESS
    {
        private static string sp_Name = "SP_CHITIET_PHHIEUXUAT";
        public static void ExcuteQueryString(string ACTION, CHITIET_PHIEUXUAT_ENTITY ctpx)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                if (ctpx != null)
                {
                    com.Parameters.AddWithValue("@MACTPX", ctpx.MACTPX);
                    com.Parameters.AddWithValue("@MAPX", ctpx.MAPX);
                    com.Parameters.AddWithValue("@MAXE", ctpx.MAXE);
                    com.Parameters.AddWithValue("@SOLUONG", ctpx.SOLUONG);
                    com.Parameters.AddWithValue("@DONGIAXUAT", ctpx.DONGIAXUAT);
            

                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
        public static DataSet GETDATATABLE(string ACTION, CHITIET_PHIEUXUAT_ENTITY ctpx)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                if (ctpx != null)
                {
                    com.Parameters.AddWithValue("@MACTPX", ctpx.MACTPX);
                    com.Parameters.AddWithValue("@MAPX", ctpx.MAPX);
                    com.Parameters.AddWithValue("@MAXE", ctpx.MAXE);
                    com.Parameters.AddWithValue("@SOLUONG", ctpx.SOLUONG);
                    com.Parameters.AddWithValue("@DONGIAXUAT", ctpx.DONGIAXUAT);

                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
    }
